﻿import QtQuick
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
import QtCore
import FilUI

import "../controls"

FilScrollablePage {
    id: control

    property int rightScrollableMargin: 17
    property int frameSpacing: 12

    FilFrame {
        Layout.fillWidth: true
        Layout.rightMargin: control.rightScrollableMargin
        height: 100
        padding: 10
        color: "transparent"
        property bool isInitChecked: false
        ColumnLayout {
            spacing: 10
            FilText {
                text: qsTr("Debug Enable")
            }
            FilToggleSwitch {
                id: id_filtoggleswitch__debugenable
                checked: AppInfo.debugEnable
                clickListener: function() {
                    if (checked) {
                        checked = false
                        AppInfo.debugEnable = false
                        SettingsHelper.saveDebugEnable(false)
                    } else {
                        id_filcontentdialog__warning.open()
                    }
                }
            }
        }
        FilContentDialog {
            id: id_filcontentdialog__warning
            title: qsTr("Warning")
            message: qsTr("You have entered debug mode, which may cause unexpected errors.")
            buttonFlags: FilContentDialogType.NegativeButton | FilContentDialogType.PositiveButton
            onNegativeClicked: {
                id_filtoggleswitch__debugenable.checked = false
            }
            onPositiveClicked: {
                id_filtoggleswitch__debugenable.checked = true
                AppInfo.debugEnable = true
                SettingsHelper.saveDebugEnable(true)
                showWarning(qsTr("Debug mode has been enabled"), 2000)
            }
        }
        Component.onCompleted: {
            if (AppInfo.debugEnable) {
                showWarning(qsTr("Debug mode has been enabled"), 0, qsTr("This will lead to unexpected errors."))
            }
        }
    }
    FilFrame {
        Layout.fillWidth: true
        Layout.rightMargin: control.rightScrollableMargin
        height: 100
        padding: 10
        color: "transparent"
        ColumnLayout {
            spacing: 5
            FilText {
                text: qsTr("Test")
            }
            RowLayout {
                FilButton {
                    text: qsTr("Test Crash")
                    onClicked: {
                        AppInfo.testCrash()
                    }
                }
                FilButton {
                    text: qsTr("Restart")
                    onClicked: {
                        Qt.exit(931)
                    }
                }
            }
        }
    }
    FilFrame {
        Layout.fillWidth: true
        Layout.rightMargin: control.rightScrollableMargin
        height: 100
        padding: 10
        color: "transparent"
        ColumnLayout {
            spacing: 5
            FilText {
                text: qsTr("Logger")
            }
            FilButton {
                text: qsTr("Open Directory")
                onClicked: {
                    var url = StandardPaths.writableLocation(StandardPaths.AppLocalDataLocation) + "/log"
                    var str = FilTools.toLocalPath(url).replace(/\\/g, "/")
                    console.log("onClicked Open Directory ", str)
                    FilTools.showDirInExplorer(str)
                }
            }
        }
    }
    FilFrame {
        Layout.fillWidth: true
        Layout.rightMargin: control.rightScrollableMargin
        height: 100
        padding: 10
        color: "transparent"
        ColumnLayout {
            spacing: 5
            FilText {
                text: qsTr("Config File")
            }
            FilButton {
                text: qsTr("Open In Notepad")
                onClicked: {
                    FilTools.showFileTextInNotepad(SettingsHelper.getIniFilePath())
                }
            }
        }
    }
}
